//
//  CYNET.h
//  UniversalApp
//
//  Created by 志刚杨 on 2018/1/26.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import <Foundation/Foundation.h>

/** 请求成功的Block */
typedef void(^CYHttpRequestSuccess)(id responseObject);

/** 请求失败的Block */
typedef void(^CYHttpRequestFailed)(NSString *error);

typedef void(^CYHttpRequestFailedV3)(NSString *error,NSInteger code);

/** 缓存的Block */
typedef void(^CYHttpRequestCache)(id responseCache);


@interface CYNET : NSObject

/**
 *  POST请求,自动缓存
 *
 *  @param URL           请求地址
 *  @param parameters    请求参数
 *  @param responseCache 缓存数据的回调
 *  @param success       请求成功的回调
 *  @param failure       请求失败的回调
 *
 *  @return 返回的对象可取消请求,调用cancel方法
 */
+ (__kindof NSURLSessionTask *)POST:(NSString *)URL
                         parameters:(id)parameters
                      responseCache:(CYHttpRequestSuccess)responseCache
                            success:(CYHttpRequestSuccess)success
                            failure:(CYHttpRequestFailed)failure hasCache:(BOOL)cache;

//这里因为数据返回格式修改 20180227的接口不再统一返回data修改

+ (__kindof NSURLSessionTask *)POSTv2:(NSString *)URL
                         parameters:(id)parameters
                      responseCache:(CYHttpRequestSuccess)responseCache
                            success:(CYHttpRequestSuccess)success
                            failure:(CYHttpRequestFailed)failure hasCache:(BOOL)cache;
//返回code错误码状态
+ (__kindof NSURLSessionTask *)POSTv3:(NSString *)URL
                           parameters:(id)parameters
                        responseCache:(CYHttpRequestSuccess)responseCache
                              success:(CYHttpRequestSuccess)success
                              failure:(CYHttpRequestFailedV3)failure hasCache:(BOOL)cache;


@end
